From 4fcc99a30eddcb666afca8b699c5dff9f026b39b Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 29 Sep 2014 21:49:05 +0000 Subject: [PATCH] Matt Hague adds support for OSM way center tags. --- gpsbabel/osm.cc | 40 ++++- gpsbabel/reference/osm-center-data.gpx | 199 +++++++++++++++++++++++++ gpsbabel/reference/osm-center-data.xml | 77 ++++++++++ gpsbabel/testo.d/osm.test | 3 + 4 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 gpsbabel/reference/osm-center-data.gpx create mode 100644 gpsbabel/reference/osm-center-data.xml diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index 9db63fc14..a580bd1f2 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -50,7 +50,7 @@ static route_head* rte; static Waypoint* wpt; static xg_callback osm_node, osm_node_tag, osm_node_end; -static xg_callback osm_way, osm_way_nd, osm_way_tag, osm_way_end; +static xg_callback osm_way, osm_way_nd, osm_way_tag, osm_way_center, osm_way_end; static xg_tag_mapping osm_map[] = { @@ -60,6 +60,7 @@ xg_tag_mapping osm_map[] = { { osm_way, cb_start, "/osm/way" }, { osm_way_nd, cb_start, "/osm/way/nd" }, { osm_way_tag, cb_start, "/osm/way/tag" }, + { osm_way_center, cb_start, "/osm/way/center" }, { osm_way_end, cb_end, "/osm/way" }, { NULL, (xg_cb_type)0, NULL } }; @@ -579,6 +580,8 @@ static void osm_way(xg_string args, const QXmlStreamAttributes* attrv) { rte = route_head_alloc(); + // create a wpt to represent the route center if it has a center tag + wpt = new Waypoint; if (attrv->hasAttribute("id")) { rte->rte_desc = "osm-id " + attrv->value("id").toString(); } @@ -607,6 +610,7 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv) { QString key, value; QString str; + signed char ikey; if (attrv->hasAttribute("k")) { key = attrv->value("k").toString(); @@ -620,9 +624,35 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv) if (key == QLatin1String("name")) { if (rte->rte_name.isEmpty()) { rte->rte_name = str; + wpt->shortname = str; } } else if (key == QLatin1String("name:en")) { rte->rte_name = str; + + wpt->shortname = str; + // The remaining cases only apply to the center node + } else if ((ikey = osm_feature_ikey(key)) >= 0) { + wpt->icon_descr = osm_feature_symbol(ikey, CSTR(value)); + } else if (key == "note") { + if (wpt->notes.isEmpty()) { + wpt->notes = str; + } else { + wpt->notes += "; "; + wpt->notes += str; + } + } +} + +static void +osm_way_center(xg_string args, const QXmlStreamAttributes* attrv) +{ + wpt->wpt_flags.fmt_use = 1; + + if (attrv->hasAttribute("lat")) { + wpt->latitude = attrv->value("lat").toString().toDouble(); + } + if (attrv->hasAttribute("lon")) { + wpt->longitude = attrv->value("lon").toString().toDouble(); } } @@ -633,6 +663,14 @@ osm_way_end(xg_string args, const QXmlStreamAttributes*) route_add_head(rte); rte = NULL; } + + if (wpt) { + if (wpt->wpt_flags.fmt_use) { + waypt_add(wpt); + } else { + wpt = NULL; + } + } } static void diff --git a/gpsbabel/reference/osm-center-data.gpx b/gpsbabel/reference/osm-center-data.gpx new file mode 100644 index 000000000..4a07f493c --- /dev/null +++ b/gpsbabel/reference/osm-center-data.gpx @@ -0,0 +1,199 @@ + + + + + + osm-id 1 + osm-id 1 + osm-id 1 + + + osm-id 2 + osm-id 2 + osm-id 2 + + + osm-id 3 + osm-id 3 + osm-id 3 + + + osm-id 4 + osm-id 4 + osm-id 4 + + + osm-id 5 + osm-id 5 + osm-id 5 + + + osm-id 6 + osm-id 6 + osm-id 6 + + + osm-id 7 + osm-id 7 + osm-id 7 + + + osm-id 8 + osm-id 8 + osm-id 8 + + + osm-id 9 + osm-id 9 + osm-id 9 + + + osm-id 10 + osm-id 10 + osm-id 10 + + + osm-id 11 + osm-id 11 + osm-id 11 + + + osm-id 12 + osm-id 12 + osm-id 12 + + + osm-id 13 + osm-id 13 + osm-id 13 + + + osm-id 14 + osm-id 14 + osm-id 14 + + + osm-id 15 + osm-id 15 + osm-id 15 + + + osm-id 16 + osm-id 16 + osm-id 16 + + + My Restuarant + My Restuarant + My Restuarant + Restaurant + + + My Pub + My Local Pub + My Local Pub + Bar + + + My Store + My Local Store; Sells Food + My Local Store; Sells Food + Convenience Store + + + My Restuarant + osm-id 1 + + osm-id 1 + osm-id 1 + osm-id 1 + + + osm-id 2 + osm-id 2 + osm-id 2 + + + osm-id 3 + osm-id 3 + osm-id 3 + + + osm-id 4 + osm-id 4 + osm-id 4 + + + + My Pub + osm-id 2 + + osm-id 5 + osm-id 5 + osm-id 5 + + + osm-id 6 + osm-id 6 + osm-id 6 + + + osm-id 7 + osm-id 7 + osm-id 7 + + + osm-id 8 + osm-id 8 + osm-id 8 + + + + My Pub + osm-id 3 + + osm-id 9 + osm-id 9 + osm-id 9 + + + osm-id 10 + osm-id 10 + osm-id 10 + + + osm-id 11 + osm-id 11 + osm-id 11 + + + osm-id 12 + osm-id 12 + osm-id 12 + + + + My Store + osm-id 3 + + osm-id 13 + osm-id 13 + osm-id 13 + + + osm-id 14 + osm-id 14 + osm-id 14 + + + osm-id 15 + osm-id 15 + osm-id 15 + + + osm-id 16 + osm-id 16 + osm-id 16 + + + diff --git a/gpsbabel/reference/osm-center-data.xml b/gpsbabel/reference/osm-center-data.xml new file mode 100644 index 000000000..43d90a75a --- /dev/null +++ b/gpsbabel/reference/osm-center-data.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + diff --git a/gpsbabel/testo.d/osm.test b/gpsbabel/testo.d/osm.test index d9a76d17c..d2cab0fa1 100644 --- a/gpsbabel/testo.d/osm.test +++ b/gpsbabel/testo.d/osm.test @@ -4,5 +4,8 @@ rm -f ${TMPDIR}/osm-* gpsbabel -i osm -f ${REFERENCE}/osm-data.xml -o gpx -F ${TMPDIR}/osm-data.gpx -o osm -F ${TMPDIR}/osm-out.xml compare ${REFERENCE}/osm-data.gpx ${TMPDIR}/osm-data.gpx +gpsbabel -i osm -f ${REFERENCE}/osm-center-data.xml -o gpx -F ${TMPDIR}/osm-center-data.gpx -o osm -F ${TMPDIR}/osm-center-out.xml +compare ${REFERENCE}/osm-center-data.gpx ${TMPDIR}/osm-center-data.gpx + # FIXME: implement a test for OSM writer, if possible. # compare ${REFERENCE}/osm-data.xml ${TMPDIR}/osm-out.xml -- 2.30.2